package com.yandadeyu.springBoot.controller;

import com.yandadeyu.springBoot.config.MyProperty;
import com.yandadeyu.springBoot.domain.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.UUID;

/**
 * Created by Administrator on 2018/6/8.
 */
//restController 的意思就是这个控制器的所有的方法都是以json的格式输出也就是问
@RestController
public class HelloWorldController {

    @Autowired
    private CustomerRepository customerRepository;
    @RequestMapping("/hello")
    public String sayHello() {
        return "hello world";
    }

    /**
     * 输出普通类型的文本
     * @return
     */
    @RequestMapping("/goodbye")
    public String goodBye() {
        return "hello world";
    }

    /**
     *  直接可以输出JSON类型内容
     * @return
     */
    @RequestMapping("/getUser")
    @Cacheable(value="getuser")
    public User getUser(String userId) {
        User user=new User();
         user.setAge(100);
         user.setName("yanbin");
        return user;
    }

    @RequestMapping("/uid")
    String uid(HttpSession session) {
        UUID uid = (UUID) session.getAttribute("uid");
        if (uid == null) {
            uid = UUID.randomUUID();
        }
        session.setAttribute("uid", uid);
        return session.getId();
    }



}
